#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> ipt[10086];
int dp[10086] = {};

int main(int argc, char const *argv[])
{
    int n, k, t, tt;
    cin >> n >> k;
    for (int i = 0; i < k; i++)
    {
        cin >> t >> tt;
        ipt[t].push_back(tt);
    }

    for (int i = n; i >= 1; i--)
    {
        if (!ipt[i].size())
        {
            dp[i] = dp[i + 1] + 1;
        }
        else
        {
            int mx = 0;
            for (int j = 0; j < ipt[i].size(); j++)
            {
                mx = max(mx, dp[i + ipt[i][j]]);
            }
            dp[i] = mx;
        }
    }
    
    // for (int i = 1; i <= n; i++)
    // {
    //     cout << dp[i] << " ";
    // }

    cout << dp[1];
    
    return 0;
}
